package inporter;

import main.*;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

public class TokenInporter 
{
	private ArrayList<tokens> arlTokenAll = new ArrayList<tokens>();
	private TokenArrayProcessor clsTAProcessor = new TokenArrayProcessor(arlTokenAll);
	
	public ArrayList<tokens> arlInporter(String pFileLocation)
	{
		try
		{
			FileReader reader = new FileReader(pFileLocation);
			BufferedReader br = new BufferedReader(reader);
			String strCntLine = null;
			int intCntLine = 1;
			  
			while((strCntLine = br.readLine()) != null) 
			{
				clsTAProcessor.initialIndex();
				clsTAProcessor.setTokens(tokenReorganization(strCntLine), intCntLine);
				
				intCntLine ++;
			}
			arlTokenAll = clsTAProcessor.getTokensArray();
			
			br.close();
			reader.close();
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}	
		
		return arlTokenAll;
	}
	
	private ArrayList<String> tokenReorganization(String pCntLine)
	{
		ArrayList<String> arlCntLine = new ArrayList<String>();
		
		String strTokenTemp[] = pCntLine.split(" ");
		for (int i = 0; i < strTokenTemp.length; i++)
		{
			if (!arlCntLine.contains(strTokenTemp[i].trim()))
			{
				arlCntLine.add(strTokenTemp[i].trim());
			}
		}
		
		return arlCntLine;
	}
}

